#!/bin/bash

VERSION=$(./SCYLLA-VERSION-GEN)
SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE)
SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE)

. /etc/os-release

if [ "$SCYLLA_VERSION" = "666.development" ]; then
    if [ "$ID" = "ubuntu" ]; then
        CODENAME=`lsb_release -c|awk '{print $2}'`
        if [ "$CODENAME" = "trusty" ]; then
            CODENAME=ubuntu
        fi
        echo http://downloads.scylladb.com/deb/unstable/$CODENAME/master/latest/scylla.list
    elif [ "$ID" = "centos" ]; then
        echo http://downloads.scylladb.com/rpm/unstable/centos/master/latest/scylla.repo
    elif [ "$ID" = "fedora" ]; then
        echo http://downloads.scylladb.com/rpm/unstable/fedora/master/latest/scylla.repo
    else
        echo "Unsupported distribution."
        exit 1
    fi
else
    REPO_VERSION=$(echo $SCYLLA_VERSION |sed -e "s/^\([0-9]*\.[0-9]*\).*/\1/")
    if [ "$ID" = "ubuntu" ]; then
        CODENAME=`lsb_release -c|awk '{print $2}'`
        echo http://downloads.scylladb.com/deb/ubuntu/scylla-$REPO_VERSION-$CODENAME.list
    elif [ "$ID" = "centos" ]; then
        echo http://downloads.scylladb.com/rpm/centos/scylla-$REPO_VERSION.repo
    elif [ "$ID" = "fedora" ]; then
        echo http://downloads.scylladb.com/rpm/fedora/scylla-$REPO_VERSION.repo
    else
        echo "Unsupported distribution."
        exit 1
    fi
fi
